/* ----------------------------- Marlin Toolkit----------------------------*
Authors : Daniel Randle, Alex Bourne
Date Created : Mar 1 2013

File:
	mapwindow.h

Description:
	This file contains the necessary declarations of the map window class which is
	the viewport for the GameMap object.
*---------------------------------------------------------------------------*/

#ifndef MAPWINDOW_H
#define MAPWINDOW_H


// Includes
#include <myGL\glew.h>
#include <qgl.h>
#include <global.h>
#include <nsmath3d.h>
#include <map>
#include <boost\timer.hpp>
#include <nsframebufferobject.h>

#include <nslight.h>


// Class declarations
class NSShader;
class NSMesh;
class NSObjectReferenceSet;
class NSObjectSet;
class NSShaderSet;
class NSCamera;
class NSObjectReference;
class NSShadowFrameBuffer;
class NSPickingFrameBuffer;
class NSEngine;
class InputMapping;
class QTimer;
#ifdef DEBUG
class Debug;
#endif

/* ---------------------------------Class MapWindow-----------------------------*

Inherits : QGLWidget

Namespace : ToolkitGui

Description:
	This class is the viewport for the map being edited. It will re-implement the initialize,
	resize, and paint GL functions to accomplish the Toolkit drawing functions. The main
	container object used is the GameMap class from the NobleSteed engine. This class
	will be responsible for drawing the objects in the class to the view.

*-----------------------------------------------------------------------------*/


namespace ToolkitGui
{
	class MainWindow;

	class MapWindow : public QGLWidget
	{

		Q_OBJECT

	public:
		// ctor
		MapWindow(const QGLFormat & form, QWidget * parent, MainWindow * mainWin, const QGLWidget * shareWidget = 0, Qt::WindowFlags f = 0);
		~MapWindow();

		NSEngine * getEngine();

		void postUpdate();

		#ifdef DEBUG
		void setDebug(Debug *debug);
		#endif

	public slots:
		void OnIdle();
		void onActivateBuild();

	protected:
		void initializeGL();
		void resizeGL(int width,int height);
		void paintGL();
		void keyPressEvent(QKeyEvent * keyEvent);
		void keyReleaseEvent ( QKeyEvent * keyEvent );
		void mouseMoveEvent( QMouseEvent * mevent);
		void mousePressEvent( QMouseEvent * mevent);
		void mouseReleaseEvent( QMouseEvent * mevent);
		void mouseDoubleClickEvent ( QMouseEvent * event );
		void wheelEvent(QWheelEvent * wevent);

	private:
		void _initObjects();
		void _setupUi();
		void _setupConnections();

		bool guiUpdate;
		
		InputMapping * inputMap;
		NSEngine * engine;
		MainWindow * mainWindow;

		boost::timer timer;
		
		#ifdef DEBUG
		Debug * d;
		#endif
	};
}

#endif // MAPWINDOW_H